home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cswitc
/
mt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-19
|
2KB
|
97 lines
#include "stdio.h"
#include "dos.h"
#include "tcb.h"
extern int tcblist[];
extern int readyq[];
extern int swap_count;
extern int idlecount;
extern int noswap;
extern int mustswap;
extern int findlargemem();
int lines_read;
char msgbuf[1024];
extern void relinq();
int sem4test();
int readfile();
main()
{
union REGS ir;
unsigned int j,k;
long lj;
k=0;
puts("Multitasking test.");
start_mt();
start_swapping();
j=findlargemem();
lj=(long)j * 16L;
printf("%ld bytes available\n",lj);
puts("waiting for semaphore to be set ");
spawn(sem4test,4);
while(sem_test(1)==-1) relinq();
sem_attach(1);
sem_release(1);
puts("got semaphore #1");
spawn(readfile,4);
for(;;)
{
printf("Loop = %d idle=%d swap=%d read=%d\n",
k++,idlecount,swap_count, lines_read);
if(kbhit()) break;
if(testmsg(1))
{
recvmsg(1,msgbuf,1000);
puts(msgbuf);
}
}
end_mt();
getch();
}
sem4test()
{
int j,k,n;
union REGS ir;
sem_attach(1);
sleep(3);
sem_release(1);
spawn_exit();
}
readfile()
{
FILE *fp;
char buf[120];
union REGS ir;
int j;
fp=fopen("mt.c","r");
for(;;)
{
if(fgets(buf,80,fp)==NULL) break;
lines_read++;
relinq();
}
send_md_msg(1,"\n\n\n\nWere done now\n\n\n", 24);
fclose(fp);
lines_read+=1000;
spawn_exit();
}